package pathways;

/**
 * Title:        Pathways
 * Description:  Pure Java version of the Pathways Project.
 * Copyright:    Copyright (c) 2002
 * Company:      Ants Technologies
 * @author Veejay Sani
 * @version 1.0
 */

/*
  The Substrate points are as show below
   -------
  |   P1  |
  |P0   P2|
  |   P3  |
   -------
*/

import java.awt.Point;
import java.awt.Rectangle;

public class CCoOrdinates {

  public CCoOrdinates(Rectangle rectangle)
  {
    p0 = new Point();
    p1 = new Point();
    p2 = new Point();
    p3 = new Point();

    setRect(rectangle);
  }

  public Rectangle getRect()
  {
    return rect;
  }

  public void setRect(Rectangle rectangle)
  {
  /*
    The Substrate points are as show below
     -------
    |   P1  |
    |P0   P2|
    |   P3  |
     -------
  */

    rect = rectangle;
    Point topleft = new Point(rect.x,rect.y);
    int height = rect.height;
    int width = rect.width;

    p0.x = topleft.x;
    p0.y = topleft.y + height/2;

    p1.x = topleft.x + width/2;
    p1.y = topleft.y;

    p2.x = topleft.x + width;
    p2.y = p0.y;

    p3.x = p1.x;
    p3.y = p1.y + height;
  }

  public Point getPoint0()
  {
  /*
    The Substrate points are as show below
     -------
    |   P1  |
    |P0   P2|
    |   P3  |
     -------
  */
    return p0;
  }

  public Point getPoint1()
  {
    return p1;
  }

  public Point getPoint2()
  {
    return p2;
  }

  public Point getPoint3()
  {
    return p3;
  }

  public Point getPoint(int pointNum)
  {
    Point p;

    switch(pointNum)
    {
      case 0:
        p = getPoint0();
        break;
      case 1:
        p = getPoint1();
        break;
      case 2:
        p = getPoint2();
        break;
      case 3:
        p = getPoint3();
        break;
      default:
        p = null;
    }

    return p;
  }

  public void moveRect(int dx, int dy)
  {
    Rectangle r = new Rectangle(rect.x + dx, rect.y + dy,rect.width,rect.height);

    setRect(r);
  }

  private Point p0;
  private Point p1;
  private Point p2;
  private Point p3;
  private Rectangle rect;
}